home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #5 / Amiga Plus CD - 2000 - No. 5.iso / Tools / Dev / fpc / source / docs / objectex / ex38.pp < prev    next >
Encoding:
Text File  |  2000-01-01  |  649 b   |  29 lines

  1. Program ex38;
  2.  
  3. { Program to demonstrate the TStrCollection.Compare method }
  4.  
  5. Uses Objects,Strings;
  6.  
  7. Var C : PStrCollection;
  8.     S : String;
  9.     I : longint;
  10.     P : Pchar;
  11.     
  12. begin
  13.   Randomize;
  14.   C:=New(PStrCollection,Init(120,10));
  15.   C^.Duplicates:=True; { Duplicates allowed }
  16.   Writeln ('Inserting 100 records at random places.');
  17.   For I:=1 to 100 do
  18.     begin
  19.     Str(Random(100),S);
  20.     S:='String with value '+S;
  21.     P:=StrAlloc(Length(S)+1);
  22.     C^.Insert(StrPCopy(P,S));
  23.     end;
  24.   For I:=0 to 98 do
  25.     With C^ do
  26.       If Compare (At(I),At(I+1))=0 then 
  27.         Writeln ('Duplicate string found at position ',I);
  28.   Dispose(C,Done);
  29. end.